import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const $cache 			= $Lazy.file(()=>import('#private/cache-api'))
const $time 			= $Lazy.file(()=>import('@com/utils/time'))
const Title				= $Lazy.load(()=>import('#tp/title/title'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys: [],
		// 搜索表单列表
		forms: [
			{ label: '条码号',	name: 'spec_code' },
			{ label: '医院名称',	name: 'hosp_id',			type:'select',	loading:true },
			{ label: '录入时间',	names: ['start_date', 'end_date'], 	type:'date-range', 	loading:true },
		],
		content: {},
	}
	model = {}
	dic = {}
	
	componentDidMount(){
		this.getSelect()
		$time.then(f=>{
			const arr = f.duration['2-0-24']()
			this.resetModel = { start_date: arr[0], end_date: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			this.fetch()
		})
		
	}
	getSelect = () => {
		const { forms } = this.state
		$cache.then( async f => {
			$fn.setRow( forms, 'hosp_id', await f.getCache({ api:'hospital' }) )
			this.dic = await f.getDicCache({ code: [ 45700, 21000, 42000, 69700, 30000, 87000 ]})
			this.dic.collect_type = f.collect_type
			this.setState({forms})
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'spec-case-info/doubleLog', {isIndex: true})
	controls = () => [
		Controls.back.call(this,{refresh:true, refreshName:'errorRefresh'} ),   														// 返回
	]
	
	// 表单
	cols = [
		{ title: '申请单条码',		dataIndex: 'spec_code', 		...$fn.table.spec_code },
		{ title: '送检单位', 		dataIndex: 'hosp_name', 		width: 200 },
		{ title: '操作人',			dataIndex: 'operator_name', 	...$fn.table.name },
		{ title: '操作时间', 		dataIndex: 'operator_at', 		...$fn.table.time },
		{ title: '描述',			dataIndex: 'title', 			width:180 },
	]
	getName(dicCode, text, name='name',value='value'){
		const { dic } = this
		if($fn.hasArray(dic[dicCode])){
			const rows = dic[dicCode].filter(v=> {
				if(isNaN(+text)){
					return v[value] === text
				}else{
					return +v[value] === +text
				}
			})
			return $fn.hasArray(rows) ? rows[0][name] : ''
		}else{
			return ''
		}
	}
	
	render(){
		const {content} = this.state
		return (
			<>
				{/* 搜索 */}
				{ SearchForm.call(this,{timeStr:'2-0-24'}) }
				{/* 表格 */}
				{ Table.call(this, {type: 1, isIndex: true, onRow:({content})=>this.setState({content}) } ) }
				{/* 录入详情 */}
				<div className='plr10 pb10'>
					<Title title='录入详情' noPadding style={{border:0,height:26}} />
					<div className='fv  bor1 p10'>
						<div className='fxmj mb5'>
							<div className='ex mr5'><span>姓名：</span><span>{content.patient_name}</span></div>
							<div className='ex mr5'><span>性别：</span><span>{this.getName('45700',content.sex, 'name', 'code')}</span></div>
							<div className='ex mr5'>
								<span>年龄一：</span><span>{content.age_first_val}</span>
								<span className='ml10'>年龄类型一：</span><span>{this.getName('30000',content.age_first_type, 'name', 'code')}</span>
							</div>
							<div className='ex mr5'>
								<span>年龄二：</span><span>{content.age_second_val}</span>
								<span className='ml10'>年龄类型二：</span><span>{this.getName('30000',content.age_second_type, 'name', 'code')}</span>
							</div>
							<div className='ex mr5'><span>门诊/住院号：</span><span>{content.outpatient}</span></div>
						</div>
						<div className='fxmj mb5'>
							<div className='ex mr5'><span>床号：</span><span>{content.bed_no}</span></div>
							<div className='ex mr5'><span>送检科室：</span><span>{content.department_name}</span></div>
							<div className='ex mr5'><span>送检医生：</span><span>{content.doctor}</span></div>
							<div className='ex mr5'><span>医院标识：</span><span>{content.hosp_identification}</span></div>
							<div className='ex mr5'><span>医生电话：</span><span>{content.doctor_phone}</span></div>
						</div>
						<div className='fxmj mb5	'>
							<div className='ex mr5'><span>受检人电话：</span><span>{content.patient_phone}</span></div>
							<div className='ex'>
								<span>采样日期：</span><span>{content.samp_date}</span>
								<span className='ml10'>采样时间：</span><span>{content.samp_time}</span>
							</div>
							<div className='ex mr5'><span>备注：</span><span>{content.remark}</span></div>
							<div className='ex mr5'><span>标本性状：</span><span>{this.getName('21000',content.spec_traits, 'name', 'code')}</span></div>
							<div className='ex mr5'><span>采集类型：</span><span>{this.getName('collect_type',content.collect_type)}</span></div>
						</div>
						<div className='fxmj mb5'>
							<div className='ex mr5'><span>证件类型：</span><span>{this.getName('87000',content.card_type, 'name', 'code')}</span></div>
							<div className='ex mr5'><span>证件号：</span><span>{content.card_no}</span></div>
							<div className='ex mr5'><span>受检人类型：</span><span>{this.getName('42000',content.case_type, 'name', 'code')}</span></div>
							<div className='ex mr5'><span>病理固定时间：</span><span>{content.bingli_coll_time}</span></div>
							<div className='ex mr5'><span>病理离体时间：</span><span>{content.bingli_take_time}</span></div>
						</div>
						<div className='fxmj mb5'>
							<div className='ex mr5'><span>临床诊断：</span><span>{content.diagnosis_info}</span></div>
							<div className='ex mr5'><span>识别标签：</span><span>{this.getName('69700',content.tags, 'name', 'code')}</span></div>
							<div className='ex mr5'><span>备用1：</span><span>{content.user_defined1}</span></div>
							<div className='ex mr5'><span>备用2：</span><span>{content.user_defined2}</span></div>
							<div className='ex mr5'><span>备用3：</span><span>{content.user_defined3}</span></div>
						</div>
						<div className='fxmj mb5'>
							<div className='ex mr5'><span>备用4：</span><span>{content.user_defined4}</span></div>
							<div className='ex mr5'><span>备用5：</span><span>{content.user_defined5}</span></div>
							<div className='ex mr5'><span>备用6：</span><span>{content.user_defined6}</span></div>
							<div className='ex mr5'><span>备用7：</span><span>{content.user_defined7}</span></div>
							<div className='ex mr5'><span>备用8：</span><span>{content.user_defined8}</span></div>
						</div>
						<div className='fxm mb5'>
							<div style={{width:'20%'}}><span>备用9：</span><span>{content.user_defined9}</span></div>
							<div style={{width:'20%'}}><span>备用10：</span><span>{content.user_defined10}</span></div>
						</div>
					</div>
				</div>
			</>
		)
	}
}

export default Index